package com.sfhk.web;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/LogOutServlet")
public class LogOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、销毁session
        request.getSession().invalidate();
        //2、清空Cookie
        String uri = request.getContextPath() + "/";
        Cookie c = new Cookie("username","");
        c.setPath(uri);
        c.setMaxAge(0);
        response.addCookie(c);
        c = new Cookie("password","");
        c.setPath(uri);
        c.setMaxAge(0);
        response.addCookie(c);
        //2、跳转页面
        response.sendRedirect(request.getContextPath());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
